package window;


import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class IStatisticspage {

	public JFrame iStatisticspageFrame;
	@SuppressWarnings("rawtypes")
	private JComboBox comboBox;
	private JTextField textField;
	String id="";
	String str2="";
	String[] t = {"age","title","department","course","address"};
	String[] s = { "年龄", "职称", "所在系","教授课程","联系地址" };
	/**
	 * Launch the application.
	 */

	/**
	 * Create the application.
	 */
	public IStatisticspage(String id) {
		this.id=id;
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void initialize() {
		iStatisticspageFrame = new JFrame();
		iStatisticspageFrame.setBounds(-7, 0, 1380, 736);
		iStatisticspageFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		iStatisticspageFrame.getContentPane().setLayout(null);
		ImageIcon icon=new ImageIcon("D:\\eclipse\\workspace\\TeacherInformationManagementSystem\\src\\window\\1.png");
		iStatisticspageFrame.setIconImage(icon.getImage());
		
		JLabel label = new JLabel("教师信息统计");
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setForeground(Color.DARK_GRAY);
		label.setFont(new Font("宋体", Font.BOLD, 30));
		label.setBounds(0, 50, 1364, 31);
		iStatisticspageFrame.getContentPane().add(label);
		
		JMenuBar menuBar = new JMenuBar();
		menuBar.setBounds(0, 0, 1364, 23);
		iStatisticspageFrame.getContentPane().add(menuBar);
		
		JMenu mnNewMenu = new JMenu("操作(ALT+1)");
		mnNewMenu.setHorizontalAlignment(SwingConstants.CENTER);
		mnNewMenu.setFont(new Font("幼圆", Font.PLAIN, 15));
		mnNewMenu.setForeground(Color.DARK_GRAY);
		mnNewMenu.setMnemonic('1');
		menuBar.add(mnNewMenu);
		
		JMenuItem menuItem = new JMenuItem("返回(F)");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				TeacherHomepage th=new TeacherHomepage(id);
				th.teacherHomepageFrame.setVisible(true);
				iStatisticspageFrame.dispose();
			}
		});
		menuItem.setFont(new Font("幼圆", Font.PLAIN, 13));
		menuItem.setForeground(Color.DARK_GRAY);
		menuItem.setMnemonic('F');
		mnNewMenu.add(menuItem);
		
		JMenuItem mntme = new JMenuItem("退出登录(E)");
		mntme.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Login lg=new Login();
				lg.LoginFrame.setVisible(true);
				iStatisticspageFrame.dispose();
			}
		});
		mntme.setMnemonic('E');
		mntme.setForeground(Color.DARK_GRAY);
		mntme.setFont(new Font("幼圆", Font.PLAIN, 13));
		mnNewMenu.add(mntme);
		
		JLabel lblNewLabel_1 = new JLabel("欢迎你，亲爱的");
		lblNewLabel_1.setForeground(Color.DARK_GRAY);
		lblNewLabel_1.setFont(new Font("幼圆", Font.PLAIN, 12));
		lblNewLabel_1.setBounds(10, 37, 90, 15);
		iStatisticspageFrame.getContentPane().add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("New label");
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_2.setText(id);
		lblNewLabel_2.setForeground(Color.DARK_GRAY);
		lblNewLabel_2.setFont(new Font("幼圆", Font.BOLD, 13));
		lblNewLabel_2.setBounds(98, 37, 75, 15);
		iStatisticspageFrame.getContentPane().add(lblNewLabel_2);
		
		JButton button = new JButton("统计");
		
		textField = new JTextField();
		textField.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if(e.getKeyCode()==KeyEvent.VK_ENTER)
					button.doClick();
			}
		});
		textField.setColumns(10);
		textField.setBounds(626, 151, 227, 21);
		iStatisticspageFrame.getContentPane().add(textField);
		
		JLabel label_1 = new JLabel("，请输入教师信息统计方式！");
		label_1.setForeground(Color.DARK_GRAY);
		label_1.setFont(new Font("幼圆", Font.PLAIN, 12));
		label_1.setBounds(168, 37, 202, 15);
		iStatisticspageFrame.getContentPane().add(label_1);
		
		
		comboBox = new JComboBox(s);
		comboBox.setFont(new Font("幼圆", Font.BOLD, 13));
		comboBox.setForeground(Color.DARK_GRAY);
		comboBox.setBounds(489, 150, 106, 23);
		iStatisticspageFrame.getContentPane().add(comboBox);
		
		
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(textField.getText().length()==0) JOptionPane.showMessageDialog(null, "请输入统计条件！", "error！", JOptionPane.ERROR_MESSAGE);
				else {
				for(int i=0;i<s.length;i++) {
					if(comboBox.getSelectedItem().toString().equals(s[i])) {
						str2=textField.getText();
						
						  /* System.out.println(t[i]);
						   System.out.println(str2);
						   System.out.println(s[i]);*/
						
						Statisticspage sp=new Statisticspage(id,t[i],str2);
						sp.statisticspageFrame.setVisible(true);
						iStatisticspageFrame.dispose();
						}
					}					
				}
				
				/*if(textField.getText().length()>10) 
					JOptionPane.showMessageDialog(null, "工号不得超过十位！", "error！", JOptionPane.ERROR_MESSAGE);	
				else {
				cid=textField.getText();
				Selectpage sp=new Selectpage(id,cid);
				sp.selectpageFrame.setVisible(true);
				iSelectpageFrame.dispose();
				}*/
			}
		});
		button.setForeground(Color.DARK_GRAY);
		button.setFont(new Font("幼圆", Font.BOLD, 16));
		button.setBounds(620, 580, 130, 35);
		iStatisticspageFrame.getContentPane().add(button);
		
	}

}
